package com.kfc.sales;

import java.util.List;
import java.util.Vector;




import android.app.Activity;
import android.app.ListActivity;
import android.content.Context;
import android.net.ParseException;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class ProductCategories extends ListActivity{
	private LayoutInflater mInflater;
	private Vector<RowData> data;
	RowData rd;
	static final String[] kfccategories = new String[] {
	    "Chicken", "Boxed Meals",	"Bucket Meals","Sandwhiches", "Bowls", "Snacks", "Fixins", "Salads", "Krushers", "Desserts", "Toasted Line"    	};

	
	private Integer[] imgid = {
			R.drawable.onechicken,R.drawable.fullyloaded,R.drawable.bucketmeal,R.drawable.zinger,R.drawable.chickenbowl,
	  R.drawable.spag, R.drawable.mashedpotato,R.drawable.salad,R.drawable.krushers,
	  R.drawable.tiramisu,R.drawable.twister	};	
	@Override
	    public void onCreate(Bundle savedInstanceState) {
	        super.onCreate(savedInstanceState);
	        setContentView(R.layout.productcategories);
			mInflater = (LayoutInflater) getSystemService(
					Activity.LAYOUT_INFLATER_SERVICE);
				
				data = new Vector<RowData>();
				
				for(int i=0;i<kfccategories.length;i++){
					try {
					 	rd = new RowData(kfccategories[i],i);
					    } catch (ParseException e) {
					    	e.printStackTrace();
					   }
					   data.add(rd);
				}
						
						CustomAdapter adapter = new CustomAdapter(this, R.layout.lists,
						                                     R.id.branchloc, data);
						
						setListAdapter(adapter);
						getListView().setTextFilterEnabled(true);
	        
		}
	
	 public class RowData {
	       protected String mproductcategory;
	       protected int mcategoryImage;
	       
	       RowData(String name,int img)
	       {
	    	   mproductcategory=name;
	    	   mcategoryImage = img;
	       }
	
	}
	  
 public class CustomAdapter extends ArrayAdapter<RowData> {
	  public CustomAdapter(Context context, int resource,
	                        int textViewResourceId, List<RowData> objects) {               
	 super(context, resource, textViewResourceId, objects);
	}
	      @Override
	       public View getView(int position, View convertView, ViewGroup parent) {   
	       ViewHolder holder = null;
	       TextView categoryName = null;
	       ImageView categoryImg=null;
	       RowData rowData= getItem(position);
	       if(null == convertView){
	            convertView = mInflater.inflate(R.layout.productcategorylist, null);
	            holder = new ViewHolder(convertView);
	            convertView.setTag(holder);
	        }
	             holder = (ViewHolder) convertView.getTag();
	             categoryName = holder.getCategoryName();
	             categoryName.setText(rowData.mproductcategory);                                                     
	             categoryImg=holder.getCategoryImg();
	             categoryImg.setImageResource(imgid[rowData.mcategoryImage]);    
	             return convertView;
	       }
	            private class ViewHolder {
	            private View mRow;
	            private TextView categoryName = null;
	            private ImageView categoryImg=null; 
	            public ViewHolder(View row) {
	            mRow = row;
	 }
	         public TextView getCategoryName() {
	             if(null == categoryName){
	                 categoryName = (TextView) mRow.findViewById(R.id.categoryName);
	                }
	            return categoryName;
	         }     
	         public ImageView getCategoryImg() {
	             if(null == categoryImg){
	            	 categoryImg = (ImageView) mRow.findViewById(R.id.categoryimg);
	                    }
	           return categoryImg;
	         }
	     }
	   }
	
	
	

}
